from templates.config import db


def recording(username, data):
    collection = db[username]
    collection.insert_one(data)


def chat_id(username):
    collection = db[username]
    # 检索所有文档
    cursor = collection.find({}, {"_id": 0, "chat_id": 1})
    # 遍历所有文档
    temp = 0
    for document in cursor:
        try:
            if temp < document['chat_id']:
                temp = document['chat_id']
        except KeyError:
            pass
    return temp


# print(chat_id('lisi'))
